<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>标题</td>
                    <td><input type="text" v-model="queryinfo.Title"/></td>
                </tr>
                <tr>
                    <td>优惠类型</td>
                    <td><select v-model="queryinfo.Discon">
                        <option :value="0">请选择</option>
                        <option :value="1">代金券</option>
                        <option :value="2">折扣券</option>
                        <option :value="3">兑换券</option>
                    </select></td>
                </tr>
                <tr>
                    <td>副标题</td>
                    <td><input type="text" v-model="queryinfo.Subtile"/></td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td><input type="file" @change="img"/>
                        <img :src="queryinfo.Photo" alt="" width="100" height="100" v-if="queryinfo.Photo!=''"/></td>
                </tr>
                <tr>
                    <td>库存</td>
                    <td><input type="text" v-model="queryinfo.Count"/></td>
                </tr>
                <tr>
                    <td>限领数量</td>
                    <td><input type="text" v-model="queryinfo.RersonNumber"/></td>
                </tr>
                <tr>
                    <td>消费金额</td>
                    <td><input type="text" v-model="queryinfo.AmountMonty"/></td>
                </tr>
                <tr>
                    <td>减免金额</td>
                    <td><input type="text" v-model="queryinfo.SubMonty"/></td>
                </tr>
                <tr v-if="queryinfo.Discon==2">
                    <td>折扣价</td>
                    <td><input type="text" v-model="queryinfo.Zhekou"/></td>
                </tr>
                <tr>
                    <td>开始时间</td>
                    <td><input type="date" v-model="queryinfo.BeginTime"/></td>
                </tr>
                <tr>
                    <td>结束时间</td>
                    <td><input type="date" v-model="queryinfo.EndTime"/></td>
                </tr>
                <tr>
                    <td>适应业务</td>
                    <td>
                        <input type="checkbox" v-model="queryinfo.Uservice" value="餐厅"/>餐厅
                        <input type="checkbox" v-model="queryinfo.Uservice" value="购物"/>购物
                        <input type="checkbox" v-model="queryinfo.Uservice" value="奶茶"/>奶茶
                    </td>
                </tr>
                <tr>
                    <td>使用须知</td>
                    <td><textarea v-model="queryinfo.UserDesc"></textarea></td>
                </tr>
                <tr>
                    <td>门店外键</td>
                    <td><select v-model="queryinfo.ShopId">
                        <option value="">请选择</option>
                        <option :value="item.Id" v-for="item in data1.list">{{ item.ShopName }}</option>
                    </select></td>
                </tr>
                <tr>
                    <td>服务电话</td>
                    <td><input type="text" v-model="queryinfo.Phone"/></td>
                </tr>
                <tr>
                    <td>优惠劵颜色</td>
                    <td><input type="color" v-model="queryinfo.Color"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="add" class="btn btn-success"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue';
import axios from 'axios';
import moment from 'moment';
import {useRouter,useRoute}from 'vue-router'
const router=useRouter();
const route=useRoute();

let queryinfo:any=reactive({
  "Discon": 0,
  "Title": "",
  "Subtile": "",
  "Photo": "",
  "Count": '',
  "RersonNumber": '',
  "AmountMonty": '',
  "SubMonty": '',
  "Zhekou":0,
  "BeginTime": "",
  "EndTime": "",
  "Uservice": [],
  "UserDesc": "",
  "ShopId": '',
  "Phone": "",
  "Color": "",
})

let queryinfo1:any=reactive({
    pageindex:1,
    pagesize:2,
    shopname:'',
    begintime:'',
})

let data1:any=reactive({
    list:[],
    tocount:0,
    topage:0,
})


onMounted(()=>{
    getlist1();
})

const getlist1=()=>{
    axios({
        url:'/api/Shop/Getshop',
        method:'get',
        params:queryinfo1
    })
    .then(res=>{
        console.log(res);
        data1.list=res.data.c,
        data1.tocount=res.data.tocount,
        data1.topage=res.data.topage
    })
    .catch(err=>{
        console.log(err);
    })
}

const img=(e:any)=>{
    let obj=e.target.files[0];
    let f=new FormData();
    f.append('file',obj);
    axios({
        url:'/api/ImgPhoto/Imgfpr',
        method:'post',
        data:f
    })
    .then(res=>{
        console.log(res);
        queryinfo.Photo=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}


const add=()=>{
    queryinfo.Uservice=queryinfo.Uservice.toString();
    axios({
        url:'/api/Dist/DistAdd',
        method:'post',
        data:queryinfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('标题已存在');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push('/distlist');
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>